package uz.rt.Anastruct;

import uz.rt.utils.Coordinate;
import uz.rt.utils.Itemizable;

import java.util.ArrayList;

public class Contour implements Comparable<Contour>, Itemizable<Integer, Coordinate<Double>>
{
    private ArrayList<Coordinate<Double>> coordinates = null;

    public Contour()
    {
        coordinates = new ArrayList<Coordinate<Double>>();
    }

    public int compareTo(Contour o)
    {
        if (coordinates.size() != o.coordinates.size())
            return Integer.compare(coordinates.size(), o.coordinates.size());
        for (int i = 0; i < coordinates.size(); i++)
            if (coordinates.get(i) != o.coordinates.get(i)) return coordinates.get(i).compareTo(o.coordinates.get(i));
        return 0;
    }

    public void add(Coordinate<Double> item)
    {
        coordinates.add(item);
    }

    public void edit(Integer idx, Coordinate<Double> item)
    {
        coordinates.set(idx, item);
    }

    public void removeByKey(Integer idx)
    {
        coordinates.remove(idx.intValue());
    }

    public void removeValue(Coordinate<Double> item)
    {
        coordinates.remove(item);
    }

    public int size()
    {
        return coordinates.size();
    }
}
